package com.sgolub.commanndsonline.ws.dao;

import java.util.List;

import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.sgolub.commanndsonline.ws.entity.AdvertisingRegistryItem;

/**
 * @author sgolub
 *
 */
@Repository
public class AdvertisingRegistryItemDAOImpl implements AdvertisingRegistryItemDAO {

    @Autowired
    private SessionFactory sessionFactory;
    
	public AdvertisingRegistryItem get(Integer id) {
		AdvertisingRegistryItem advertisingRegistryItem = (AdvertisingRegistryItem)sessionFactory.
								getCurrentSession().get(AdvertisingRegistryItem.class, id);
		return advertisingRegistryItem;
	}

	public void add(AdvertisingRegistryItem advertisingRegistryItem) {
		advertisingRegistryItem.setOperationExecutedStatus(0);
		sessionFactory.getCurrentSession().save(advertisingRegistryItem);

	}

	public void update(AdvertisingRegistryItem advertisingRegistryItem) {
		sessionFactory.getCurrentSession().update(advertisingRegistryItem);

	}

	public void remove(Integer id) {
		// TODO Auto-generated method stub

	}

	@SuppressWarnings("unchecked")
	public List<AdvertisingRegistryItem> list() {
		return sessionFactory.getCurrentSession().createQuery("from AdvertisingRegistryItem").list();
	}

	@SuppressWarnings("unchecked")
	public List<AdvertisingRegistryItem> listActive(){
		System.out.println("List<AdvertisingRegistryItem> listActive()");
		return sessionFactory.getCurrentSession().createQuery("from  AdvertisingRegistryItem where operationExecutedStatus = 0").list();
	}
	
	@SuppressWarnings("unchecked")
	public List<AdvertisingRegistryItem> filter() {
		return sessionFactory.getCurrentSession().createQuery("from AdvertisingRegistryItem").list();
	}

	
	
}
